<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" customClass="customWidth" destroy-on-close @closed="$emit('closed')">
		<el-form :model="form" :rules="rules" ref="dialogForm" label-width="100px" label-position="left">
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="排序号" prop="sortNo">
						<el-input-number v-model="form.sortNo" :min="1" style="width: 100%;"></el-input-number>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="油卡类型" prop="oilType">
						<sc-select v-model="form.oilType" :params="{code:'oilCard'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="发卡公司" prop="oilComp">
						<sc-select v-model="form.oilComp" :params="{code:'oilComp'}" :apiObj="$API.system.sysDic.getSysDicByCode" clearable filterable style="width: 100%"></sc-select>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="油卡编号" prop="cardCode">
						<el-input v-model="form.cardCode" placeholder="油卡编号" maxlength="180" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="油卡卡号" prop="cardNo">
						<el-input v-model="form.cardNo" placeholder="油卡卡号" maxlength="180" clearable></el-input>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="油卡密码" prop="passWord">
						<el-input v-model="form.passWord" placeholder="油卡密码" maxlength="180" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="当前状态" prop="status">
						<el-radio-group v-model="form.status">
							<el-radio-button label="0">空闲</el-radio-button>
							<el-radio-button label="1">使用中</el-radio-button>
							<el-radio-button label="2">挂失</el-radio-button>
							<el-radio-button label="3">失效</el-radio-button>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="当前余额" prop="balance">
						<el-input-number v-model="form.balance" placeholder="当前余额" :min="1" style="width: 100%;"></el-input-number>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row :gutter="24">
				<el-col :lg="12">
					<el-form-item label="办卡时间" prop="cardTime">
						<el-date-picker v-model="form.cardTime" placeholder="办卡时间" type="date" value-format="YYYY-MM-DD" style="width: 100%;"></el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :lg="12">
					<el-form-item label="持卡人" prop="cardUser">
						<el-input v-model="form.cardUser" placeholder="持卡人" maxlength="180" clearable></el-input>
					</el-form-item>
				</el-col>
			</el-row>
			<el-form-item label="备注说明" prop="remark">
				<el-input v-model="form.remark" placeholder="备注说明" maxlength="200" clearable type="textarea"></el-input>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button @click="visible=false">取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>

</template>
<script>
export default {
	emits: ['success', 'closed'],
	components: {
	},
	data() {
		return {
			visible: false,
			isSaveing: false,
			isShowMsg:false,
			mode: "add",
			titleMap: {
				add: '创建油卡',
				edit: '编辑油卡',
			},
			form: {
				sortNo:0,
				oilType: '',
				oilComp: '',
				cardCode: '',
				cardNo:'',
				passWord:'',
				status: "0",
				balance: 0,
				cardTime:'',
				cardUser:'',
				remark:''
			},
			rules: {
				cardCode: [
					{required: true, message: '油卡编号不能为空', trigger: 'blur'}
				],
				cardNo: [
					{required: true, message: '油卡卡号不能为空', trigger: 'blur'}
				],
				cardUser: [
					{required: true, message: '持卡人不能为空', trigger: 'blur'}
				],
				balance:[
					{required: true, message: '当前余额不能为空', trigger: 'blur'}
				]
			}
		}
	},
	mounted() {
	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this
		},
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.office.vehicle.insertVehicleOilCard.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.office.vehicle.updateVehicleOilCard.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		setData(data) {
			this.form.cardId = data.cardId
			this.form.sortNo = data.sortNo
			this.form.oilType = data.oilType
			this.form.oilComp = data.oilComp
			this.form.cardCode = data.cardCode
			this.form.cardNo = data.cardNo
			this.form.passWord = data.passWord
			this.form.status = data.status
			this.form.balance = data.balance
			this.form.cardTime = data.cardTime
			this.form.cardUser = data.cardUser
			this.form.remark = data.remark
		},
	}
}
</script>

<style>
.customWidth {
	width: 60%;
}
</style>
